// const cname = "login_token"
const cname = 'vue3_login_token'


// 设置 cookie
function setCookie(cvalue: string, exdays: number): void {
    exdays += 7 * 24 * 60 * 60 * 1000 // 设置过期时间为7天后
    var date: Date = new Date(exdays)
    var expires = ";expires=" + date.toUTCString()
    document.cookie = cname + "=" + cvalue + expires;
}


// 获取 cookie
function getCookie(): string {
    var name = cname + "=";
    var cookies = document.cookie.split(';');
    let str = ''
    for (var i = 0; i < cookies.length; i++) {
        var c = cookies[i].trim();
        if (c.indexOf(name) == 0) {
            str = c.substring(name.length, c.length)
            // console.log('cookie c', str)
        }
    }
    return str
}

// 清理cookie
function clearCookie(): Boolean {
    console.log('清除 cookie 完成')
    setCookie("", -1);
    return true
}


export {
    setCookie,
    getCookie,
    clearCookie
}